package com.ruoyi.common.utils;

/**
 * 内容加*显示
 * @author zhoudong
 *
 */
public class EncryptContent {
    /**
     * 加星号
     * @param userName
     * @return
     */
    public static String replaceAction(String userName) {
        if (StringUtils.isBlank(userName)) {
            return userName;
        }
        String userNameAfterReplaced = "";
        int nameLength = userName.length();
        if(nameLength < 3 && nameLength > 0){
            if(nameLength == 1){
                userNameAfterReplaced = "*";
            }else{
                // userNameAfterReplaced = userName.replaceAll(userName, "^.{1,2}");
                userNameAfterReplaced = userName;
            }
        }else{
            Integer num1,num2,num3;
            num2=(new Double(Math.ceil(new Double(nameLength) / 3))).intValue();
            num1=(new Double(Math.floor(new Double(nameLength) / 3))).intValue();
            num3=nameLength - num1- num2;
            String star= StringUtils.repeat("*", num2);
            userNameAfterReplaced = userName.replaceAll("(.{"+num1+"})(.{"+num2+"})(.{"+num3+"})","$1"+star+"$3");
        }
        return userNameAfterReplaced;
    }

}
